package com.macken.zjh.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.macken.zjh.Zjh;

public class MenuScreen extends BaseScreen {

	Image bg;
	Image topBar;
	Image bottomBar;
	ImageButton low;
	ImageButton middle;
	ImageButton high;
	Stage stage;

	public MenuScreen(Zjh game) {
		super(game);
	}

	@Override
	public void show() {
		TextureRegion trbg = load("menubg.png", 800, 480);
		bg = new Image(new TextureRegionDrawable(trbg));

		TextureAtlas altas = new TextureAtlas(Gdx.files.internal("menu.pack"));

		topBar = new Image(
				new TextureRegionDrawable(altas.findRegion("topBar")));
		topBar.setPosition(20, HEIGHT - topBar.getHeight());

		bottomBar = new Image(new TextureRegionDrawable(
				altas.findRegion("bottomBar")));
		bottomBar.setPosition(73, 0);

		int rh = 120;
		low = new ImageButton(
				new TextureRegionDrawable(altas.findRegion("low")));
		low.setPosition(5, rh);
		low.addListener(new ClickListener() {
			public void clicked(InputEvent event, float x, float y) {
				game.setScreen(new GameScreen(game));
			}
		});

		middle = new ImageButton(new TextureRegionDrawable(
				altas.findRegion("middle")));
		middle.setPosition(low.getX() + low.getWidth() + 20, rh);
		middle.addListener(new ClickListener() {
			public void clicked(InputEvent event, float x, float y) {
				game.setScreen(new EnterDeskLoad(game));
			}
		});

		high = new ImageButton(new TextureRegionDrawable(
				altas.findRegion("high")));
		high.setPosition(middle.getX() + middle.getWidth() + 20, rh);
		high.addListener(new ClickListener() {
			public void clicked(InputEvent event, float x, float y) {
				game.setScreen(new GameScreen(game));
			}
		});
		stage = new Stage(WIDTH, HEIGHT, false);
		stage.addActor(bg);
		stage.addActor(topBar);
		stage.addActor(bottomBar);
		stage.addActor(low);
		stage.addActor(middle);
		stage.addActor(high);
		Gdx.input.setInputProcessor(stage);
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

		stage.act(delta);
		stage.draw();
	}

	@Override
	public void hide() {

	}

}
